import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import typescript from "@rollup/plugin-typescript";
import alias from "@rollup/plugin-alias";
import path from "path";
import { fileURLToPath } from "url";
import postcss from "rollup-plugin-postcss";
import vue from "rollup-plugin-vue";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

export default {
  input: "src/index.ts",
  output: [
    {
      file: "dist/bundle.cjs.js",
      format: "cjs",
      exports: "named",
    },
    {
      file: "dist/bundle.esm.js",
      format: "esm",
    },
    {
      file: "dist/bundle.umd.js",
      format: "umd",
      name: "OpenLayersMap",
      globals: {
        vue: "Vue",
        "element-ui": "ELEMENT",
        ol: "Ol",
      },
    },
  ],
  external: ["vue", "element-ui", "ol"],
  plugins: [
    alias({
      entries: [
        {
          find: "@",
          replacement: path.resolve(__dirname, "src"),
        },
      ],
    }),
    resolve(),
    commonjs(),
    vue({
      css: false,
      compileTemplate: true,
    }),
    typescript({ tsconfig: "./tsconfig.json" }), // typescript 在 vue 插件之后
    postcss({
      extract: true,
      use: ["sass"],
    }),
  ],
};
